/** http://www.mazelog.com/show?8D */
#include<bits/stdc++.h>
using namespace std;

const int SZ = 6;
int mat[SZ][SZ] = {
  {4,4,2,2,2,5},
  {5,1,2,3,1,2},
  {3,3,3,2,3,4},
  {2,1,2,2,3,5},
  {3,3,3,3,4,1},
  {4,3,5,2,5,0}
};
int visited[SZ][SZ];
typedef pair<int,int> ii;
stack<ii> paths;

bool dfs(ii cur) {
  auto [x,y] = cur;
  if(visited[x][y]) return false;
  visited[x][y] = true;
  paths.push(cur);
  int dist = mat[x][y];
  if(dist==0) {
    cout << "Found" << endl;
  }
  else {
    if(x-dist>0) { dfs({x-dist,y}); }
    if(y+dist<SZ) { dfs({x,y+dist}); }
    if(x+dist<SZ) { dfs({x+dist,y}); }
    if(y-dist>0) { dfs({x,y-dist}); }
  }
  // BackTrack
  visited[x][y]=false;
  paths.pop();
  return false;
}
int main() {
  dfs({0,0});
}
